//格式化时间
//dateTime：时间戳
function getFormtTime(dateTime,flag) {
    if(dateTime != null ) {
        //若传入的dateTime为字符串类型，需要进行转换成数值，若不是无需下面注释代码
        var time = parseInt(dateTime)
        var date = new Date(time);
        //获取年份
        var YY = date.getFullYear();
        //获取月份
        var MM = (date.getMonth() + 1 < 10 ? '0'+(date.getMonth() + 1) : date.getMonth() + 1);
        //获取日期
        var DD = (date.getDate() < 10 ? '0'+date.getDate() : date.getDate());
        if(flag) { //flag为true，显示时分秒格式
            //获取小时
            var hh = (date.getHours() < 10 ? '0'+date.getHours() : date.getHours());
            //获取分
            var mm = (date.getMinutes() < 10 ? '0'+date.getMinutes() : date.getMinutes());
            ///获取秒
            var ss = (date.getSeconds() < 10 ? '0'+date.getSeconds() : date.getSeconds());
            //返回时间格式： 2020-11-09 13:14:52
            return YY + '-' + MM + '-' + DD + ' ' + hh + ':' + mm + ':' + ss;
        } else {
            //返回时间格式： 2020-11-09
            return YY + '-' + MM + '-' + DD;
        }
    } else {
        return "";
    }
}

           var u="<li>\n" +
                "      <label>姓名</label>\n" +
                "      <input id=\"name\" type=\"text\" value='' class=\"dfinput\" />\n" +
                "      <i>必填，不能超过30个字符</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <input type='text' id='customid' value='' hidden='hidden'>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>性别</label>\n" +
                "      <select id='sex' class=\"dfselect\">\n" +
                "          <option>男</option>\n" +
                "          <option selected=\"selected\">女</option>\n" +
                "      </select>\n" +
                "      <i>必选</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>所属公司名称</label>\n" +
                "      <input id=\"company\" type=\"text\" value='' class=\"dfinput\" />\n" +
                "       <i>必填，不能超过30个字符</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>联系方式</label>\n" +
                "      <input id=\"phone\" type=\"text\" value='' class=\"dfinput\" />\n" +
                "       <i>必填，不能超过30个字符</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>联系地址</label>\n" +
                "      <input id=\"address\" type=\"text\" value='' class=\"dfinput\" />\n" +
                "       <i>必填，不能超过130个字符</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>所属区域</label>\n" +
                "      <select id='area' class=\"dfselect\">\n" +
                "          <option>江西</option>\n" +
                "          <option selected=\"selected\">江苏</option>\n" +
                "          <option>浙江</option>\n" +
                "          <option>安徽</option>\n" +
                "          <option>广东</option>\n" +
                "      </select>\n" +
                "      省\n" +
                "      <i>必选</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>描述</label>\n" +
                "      <textarea class=\"textinput\" id='textinput'></textarea>\n" +
                "      <i>可选</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>状态</label>\n" +
                "      <select id='status' class=\"dfselect\">\n" +
                "          <option selected='selected' value=\"可用\">可用</option>\n" +
                "          <option value=\"不可用\">不可用</option>\n" +
                "        </select>\n" +
                "      <i>必选</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>创建人</label>\n" +
                "      <input name=\"\" type=\"text\" value='' readonly=\"readonly\" class=\"roinput\" />\n" +
                "      <i>不能编辑</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>创建时间</label>\n" +
                "      <input name=\"\" type=\"text\" value='"+getFormtTime(new Date(),true)+"' readonly=\"readonly\" class=\"roinput\" />\n" +
                "      <i>不能编辑</i>\n" +
                "    </li>\n" +
                "    <li>\n" +
                "      <label>&nbsp;</label>\n" +
                "      <input name=\"\" type=\"button\" class=\"btn\" id='sureUpdate' value=\"确定\"/>\n" +
                "      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\n" +
                "      <input name=\"\" type=\"button\" class=\"btn\" value=\"返回\" onclick=\"window.location.href='customerList.html'\"/>\n" +
                "    </li>"
            $(".forminfo").html(u)
            $("#sureUpdate").click(function () {
                var name = $("#name").val();
                var customid = $("#customid").val();
                var sex=$("#sex option:selected")
                var sex1=sex.text()
                var company=$("#company").val();
                var phone=$("#phone").val();
                var address=$("#address").val();
                var area=$("#area option:selected")
                var area1=area.text()
                var address1;
                if (area1=="江西"){
                    address1="1"
                }else if(area1=="广东"){
                    address1="2"
                }else if(area1=="江苏"){
                    address1="3"
                }else if(area1=="安徽"){
                    address1="4"
                }else if(area1=="浙江"){
                    address1="5"
                }
                var textinput=$("#textinput").val();
                var status=$("#status option:selected")
                var status1=status.text()
                $.ajax({
                    type: "post",
                    url: "/market/AddCustom",
                    data: {customname:name,sex:sex1,company:company,telephone:phone,address:address1,homeaddress:address,distract:textinput,status:status1},
                    dataType: "json",
                    success: function (r) {
                        if (r=="true"){
                            alert("增加成功！")
                            location.reload();
                        }else{
                            alert("增加失败！")
                        }
                    }
                })

            })




